iT邦幫忙

0

如何在SonarQube客製java Rules

Nat 2020-04-09 16:02:401276 瀏覽
  • 分享至 

  • xImage
  •  

這是SonarSource GitHub 針對各個語言的範例

https://ithelp.ithome.com.tw/upload/images/20200409/20126210XlaVMzR8y7.png

git clone 完畢後,即可匯入到eclipse開始進行修改

  • 為了測試所以直接進行mvn build
    https://ithelp.ithome.com.tw/upload/images/20200409/20126210JFdT90rVwA.png

  • 將build完的java-custom-rules-1.0-SNAPSHOT.jar 放到SONARQUBE_HOME/extensions/plugins
    https://ithelp.ithome.com.tw/upload/images/20200409/20126210ifkXn0XwRO.png

  • 然後重啟SonarQube,過程中發現有錯誤,原因是因為java-custom-rules太新,版本不匹配
    https://ithelp.ithome.com.tw/upload/images/20200409/20126210qVb9EWwoIP.png

  • 回到pom.xml,修改位置如下,再重新做上述的步驟
    https://ithelp.ithome.com.tw/upload/images/20200409/201262109o9eUARSq7.png

  • 成功啟動後可以到首頁,選擇Rules,透過左邊的Repository篩選MyCompany Custom Repository,就算成功了
    https://ithelp.ithome.com.tw/upload/images/20200409/20126210ma5rLFMcVK.png

Active/Inactive Rules

  • 如果要修改套用的Rules,需要先複製原本的Quality Profile
    https://ithelp.ithome.com.tw/upload/images/20200409/2012621003vlovKudW.png

  • Deactivate
    https://ithelp.ithome.com.tw/upload/images/20200409/20126210iSyFBAWDHU.png

  • Activate
    https://ithelp.ithome.com.tw/upload/images/20200409/20126210MlBrS9fIgy.png

  • 最後再將此Quality Profile設定是預設即可
    https://ithelp.ithome.com.tw/upload/images/20200409/20126210ja9vLF7H2m.png

總結

其實SonarQube針對各個開發語言的規則已經是非常嚴謹,大多情況下不會去額外新增,反而比較有可能的是將部分規則禁用

參考連結


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言